package br.nextfm.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.nextfm.dao.UsuarioDao;
import br.nextfm.model.Usuario;

public class AtualizaUsuario extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession(false);
		
		String nome = request.getParameter("nome");
		String senha = request.getParameter("senha");
		String email = request.getParameter("email");

		UsuarioDao dao = new UsuarioDao();

		Usuario comum = (Usuario) session.getAttribute("usuario");

		comum.setEmail(email);
		comum.setNome(nome);
		comum.setSenha(senha);
		
		if (!dao.update(comum)) {
			request.setAttribute("erroAtualiza", true);
		}
		
		session.setAttribute("usuario", comum);
		request.getRequestDispatcher("index.do").forward(request, response);
		
	}

}
